using System;
using System.Drawing;
using System.Reflection;
using System.Resources;
using System.IO;

namespace NewTcGui
{
	public class Start
	{
		[STAThread]
		public static void Main()
		{
			TcGuiApp tcGuiApp = new TcGuiApp();
			tcGuiApp.Run();
		}
	}
	
	public class TcGuiApp : wx.App
	{
		private TcPassFrame passFrame;
		
		public override bool OnInit()
		{
			//if (Environment.OSVersion.Platform == PlatformID.Unix) 
			{
				passFrame = new TcPassFrame(null, wx.Window.wxID_ANY, 
			                                      "Truecrypt Mounting GUI", new Point(0,0), new Size(100,100), 
			                                      wx.Window.wxMINIMIZE_BOX|wx.Window.wxCLOSE_BOX|
			                                      wx.Window.wxCAPTION|wx.Window.wxSYSTEM_MENU|
			                            wx.Window.wxMAXIMIZE_BOX|wx.Window.wxRESIZE_BORDER); 
			
				passFrame.Center();
				passFrame.Show(true);
				//wx.XmlResource.Get().InitAllHandlers();
				
			
			}
//			else
//			{
//				wx.MessageDialog dlg = new wx.MessageDialog(null, "Sorry but only Linux OS is supported",
//				                                            "OS not supported", wx.MessageDialog.wxICON_INFORMATION);
//				dlg.Show(true);
//				dlg.Center();
//			}
			
			if (TcGuiApp.IsRunningOnMono()) 
			{
				System.Console.WriteLine("You are using Mono!");
			}
			

//			FileStream fs = new FileStream("face-devilish.png", FileMode.Open, FileAccess.Read);
//			System.IO.BinaryReader binf = new System.IO.BinaryReader(fs);
//		
//			byte[] i1 = binf.ReadBytes((int) fs.Length);
//			IResourceWriter res = new ResourceWriter("Resources.resources");
//			res.AddResource("face-devilish.png", i1);
//			binf.Close();
//			fs.Close();
//			
//			fs = new FileStream("mono.png", FileMode.Open, FileAccess.Read);
//			binf = new BinaryReader(fs);
//			byte[] i2 = binf.ReadBytes((int) fs.Length);
//			res.AddResource("mono.png", i2);
//			binf.Close();
//			fs.Close();
//
//			fs = new FileStream("wx.gif", FileMode.Open, FileAccess.Read);
//			binf = new BinaryReader(fs);
//			byte[] i3 = binf.ReadBytes((int) fs.Length);
//			res.AddResource("wx.gif", i3);
//			binf.Close();
//			fs.Close();
//			res.Close();
			
			return true;
		}
		
		public static byte[] GetBytesFromAssembly(string name, string baseName)	
		{
			ResourceManager rm = new ResourceManager(baseName, Assembly.GetExecutingAssembly());
			
			return (byte[]) rm.GetObject(name);
		}
		
		public static bool IsRunningOnMono ()
		{
			return Type.GetType ("Mono.Runtime") != null;
		}
	}
}
